<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/common/includes.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="zzzzzz" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>zzzzzz</title>
	<%@ include file="/WEB-INF/common/meta.jsp" %>
	<%@ include file="/WEB-INF/common/global_style.jsp" %>
	<%@ include file="/WEB-INF/common/global_script.jsp" %>
	<script type="text/javascript" src="${ctx}/res/js/confirm_dialog.js"></script>
</head>
<body>

<%@ include file="/WEB-INF/common/header.jsp" %>

<div class="wrapper-content">
	<div id="topic_edit" class="site-wrap wrap">
		<div class="right-sidebar clearfix">
			<div class="content">
				<%@ include file="include/edit/content.jsp" %>
			</div>
			<div class="sidebar">
				<%@ include file="include/edit/sidebar.jsp" %>
			</div>
		</div>
	</div>
</div>

<div data-dom-id="confirm-dialog" class="confirm-dialog" style="display: none;">
	<div data-dom-id="confirm-message" class="confirm-message"></div>
	<div class="confirm-actions" align="right">
		<input type="button" data-dom-id="confirm-cancel" class="btn style3 medium" value="Cancel" /><input type="button" data-dom-id="confirm-ok" class="btn style1 medium mls" value="Ok" />
	</div>
</div>


<%@ include file="/WEB-INF/common/footer.jsp" %>

<script type="text/javascript">

jq(document).ready(function() {

	function initDescriptionCount() {
	try{
		var cur_length = jq('#topic_edit_description').val().length;
		jq('#topic_edit_description_character_count').text(500 - cur_length);
	}catch(err) {
		alert(err);
	}
	}
	
	jq('#topic_edit_description').bind('keyup mouseup change',function(e) {
	try{
		var cur_length = jq(this).val().length;
		jq('#topic_edit_description_character_count').text(500 - cur_length);
		jq('#topic_edit_description_preview').text(jq(this).val());
	}catch(err) {
		alert(err);
	}
	});
	
	jq("#topic_edit_form").submit(function(e) {
	try{
		var description = jq('#topic_edit_description').val();
		var pos_top = jq(this).offset().top;
		if(jq.trim(description).length === 0) {
			jq.notification({ "pos_top" : pos_top, "width" : 256, "message" : "Please describe a Scene or Moment." });
			return false;
		}else if(jq.trim(description).length > 500) {
			jq.notification({ "pos_top" : pos_top, "width" : 300, "message" : "The length of description cannot be more than 500." });
			return false;
		}else {
			return true;
		}
	}catch(err) {
		alert(err);
	}
	});
	
	jq('a[href$="#delete_topic"]').click(function(e) {
	try{
		e.preventDefault();
		var delete_link = jq(this);
		jq.confirm({"message" : "Are you sure you wanna Delete this topic?"}, function(result) {
			if(result === true) {
				window.location.href = "${ctx}/topic/delete/" + delete_link.data("topic-id");
			}
		});
	}catch(err) {
		alert(err);
	}
	});
	
	initDescriptionCount();
	
});

</script>

</body>
</html>